/**
 * Created on 2007-04-22 12:31
 */
package game;

import java.awt.Color;

/**
 * @author David Wallin
 * 
 * The highlighted block state
 */
public class BlockStateHighlighted extends BlockState
{
	/**
	 * The current mutation of the color
	 */
	private int				m_ColorMutator;
	/**
	 * The current interval, deciding how m_ColorMutator will be changed
	 * Should always be either m_ColorMutatorInterval, or -m_ColorMutatorInterval
	 */
	private int				m_CurrentColorMutatorInterval;
	/**
	 * Counts the frames
	 */
	private int				m_FrameCounter;
	/**
	 * The standard interval of change for m_ColorMutator
	 */
	private final int		m_ColorMutatorInterval = 0x111111;
	/**
	 * When m_ColorMutator hits this value, m_CurrentColorMutatorInterval is reversed
	 */
	private final int		m_UpperBorder = 0x888888;
	/**
	 * When m_ColorMutator hits this value, m_CurrentColorMutatorInterval is reversed
	 */
	private final int		m_LowerBorder = -0x888888;
	/**
	 * The number of frames between changes in m_ColorMutator
	 */
	private final int		m_ChangeColorMutatorInterval = 3;
	
	/**
	 * Constructor, calls super, initializes members
	 */
	public BlockStateHighlighted(Entity entity)
	{
		super(entity);
		
		m_ColorMutator = 0x0;
		m_CurrentColorMutatorInterval = m_ColorMutatorInterval;
		m_FrameCounter = 0;
	}
	
	/* (non-Javadoc)
	 * @see game.BlockState#draw(java.awt.Color)
	 */
	@Override
	public void draw(Color color)
	{
		m_FrameCounter++;
		
		if(m_FrameCounter > m_ChangeColorMutatorInterval)
		{
			m_FrameCounter = 0;
			
			if((m_ColorMutator >= m_UpperBorder) || (m_ColorMutator <= m_LowerBorder))
			{
				m_CurrentColorMutatorInterval = -m_CurrentColorMutatorInterval;
			}
			
			m_ColorMutator += m_CurrentColorMutatorInterval;
		}
		
		int colorValue = color.getRGB();
		colorValue += m_ColorMutator;
		Color mutatedColor = Color.getColor("", colorValue);
		
		m_RenderManager.drawSquare(m_Entity.getXpos(), m_Entity.getYpos(), m_Entity.getWidth(), m_Entity.getHeight(), mutatedColor);
	}
}
